<?php
class MenuSaveEditAction extends AdminAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'json';
	}
	
	protected function afterConstruct()
	{
		$this->parseDtds('menu','edit');
	}
	
	public function execute()
	{
		$id				= $this->context->post('id');
		$name			= $this->context->post('name');
		$link			= $this->context->post('link');
		$orderby		= $this->context->post('orderby');
		$menuService	= new MenuService();
		if(is_numeric($id) && $id)
		{
			$menuService->update($id,array('name'=>$name,'link'=>$link,'orderby'=>$orderby,));
			$this->code	= 200;
			$this->data['forward'] = C('LtUrl')->generate('Menu', 'Index');
		}
		else
		{
			$menuService->add(array('name'=>$name,'link'=>$link,'orderby'=>$orderby,));
			$this->code	= 200;
			$this->data['forward'] = C('LtUrl')->generate('Menu', 'Index');
		}
	}
}
